from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from config import MYSQL_DATABASE, MYSQL_HOST, MYSQL_PASSWORD, MYSQL_PORT, MYSQL_USERNAME

DATABASE_URL = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"

engine = create_engine(DATABASE_URL, echo=False)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()  # 所有实体类都需要继承这个 Base 对象

# 初始化数据库表（如果表不存在，则创建）
Base.metadata.create_all(bind=engine)